<?php
class Default_Model_Managers_Auth implements Zend_Auth_Adapter_Interface
{
    protected $_username;
    protected $_password;
    protected $_usersDbTable;
    
    public function __construct($username, $password)
    {
        $this->_username = $username;
        $this->_password = $password;
        $this->_usersDbTable = new Default_Model_DbTable_Users;
    }
    
    /**
     * Выполняет попытку аутентификации
     *
     * @throws Zend_Auth_Adapter_Exception Если аутентификация не может быть выполнена
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
        $user = $this->_usersDbTable->findUserByLogin($this->_username);
        $salt = $user['password_salt'];
        $passwordHashNeedle = $user['password_hash'];
        $passwordHash = md5(md5($this->_password).$salt);
        if($passwordHashNeedle == $passwordHash) {
            return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_username);
        }
        return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $this->_username);
    }
}